package com.fulu.jvm;

/**
 * 可见性问题示例
 */
public class VisibilityDemo {
    private static boolean running = true;

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            while (running) {
                // do something
            }
            System.out.println("Thread stopped.");
        });
        t.start();

        Thread.sleep(1000);
        running = false; // 主线程修改，但 t 线程可能“看不见”
    }
}